local skill = fk.CreateSkill{
  name = "iberia__zhuixi"
}

Fk:loadTranslationTable{
  [skill.name] = "追袭",
  [":"..skill.name] = "结束阶段，你可以视为对本回合失去过牌的一名角色使用一张雷【杀】。",
  [skill.name.."-prompt"] = "追袭：可以视为使用一张雷【杀】"
}

skill:addEffect(fk.EventPhaseStart, {
  anim_type = "offensive",
  can_trigger = function (self, event, target, player, data)
    if player == target and player:hasSkill(skill.name) and player.phase == Player.Finish then
      local include_targets = {}
      player.room.logic:getEventsOfScope(GameEvent.MoveCards, 999, function(e)
        for _, move in ipairs(e.data) do
          if move.from and not table.contains(include_targets, move.from) then
            for _, info in ipairs(move.moveInfo) do
              if move.from and table.contains({Card.PlayerHand, Card.PlayerEquip}, info.fromArea) then
                table.insert(include_targets, move.from)
              end
            end
          end
        end
        return false
      end, Player.HistoryTurn)

      local card = Fk:cloneCard("iberia_thunder__slash")
      card.skillName = skill.name
      include_targets = table.filter(include_targets, function(p)
        return player:canUseTo(card, p, { bypass_times = true })
      end)
      if #include_targets == 0 then return false end

      event:setCostData(self, include_targets)
      return true
    end
  end,
  on_cost = function (self, event, target, player, data)
    local include_targets = event:getCostData(self) --- @type ServerPlayer[]
    local card = Fk:cloneCard("iberia_thunder__slash")
    card.skillName = skill.name

    local tos = player.room:askToChoosePlayers(player, {
      targets = include_targets, max_num = 1, min_num = 1,
      skill_name = skill.name, prompt = skill.name.."-prompt",
      no_indicate = true, skip = true
    })
    if tos and #tos == 1 then
      event:setCostData(self, {
        card = card,
        tos = tos,
        from = player,
        skill_name = skill.name
      })
      return true
    end
  end,
  on_use = function (self, event, target, player, data)
    player.room:useCard(event:getCostData(self))
  end
})

return skill
